var express = require('express');
var app = express();
app.use(express.static('.')); // 静态文件目录
app.use(express.bodyParser());

// 接口写在这里


var data = [
    {
        id: 1,
        oid: 201704172221,
        cname: '客户1',
        ctel: '15081111111',
        sprovince: '江苏省',
        scity: '南京市',
        sdistrict: '浦口区',
        saddr: '南京大学金陵学院',
        stime: '2017-3-21-15:23',
        info: '钢材器械',
        eprovince: '江苏省',
        ecity: '南京市',
        edistrict: '浦口区',
        eaddr: '南京工业大学江浦校区',
        etime: '2017-3-24-15:23',
        price: 20000,
        zprice: 21000,
        Carnum: "苏A12345",
        Dtel: 13813813811,
        releasetime: '2017-3-24-9:00:00',
        lefttime: 15,
        carList: []
	},
    {
        id: 2,
        oid: 201704172222,
        cname: '客户2',
        ctel: '15081111111',
        sprovince: '江苏省',
        scity: '南京市',
        sdistrict: '浦口区',
        saddr: '南京大学金陵学院',
        stime: '2017-3-21-15:23',
        info: '钢材器械',
        eprovince: '江苏省',
        ecity: '南京市',
        edistrict: '浦口区',
        eaddr: '南京工业大学江浦校区',
        etime: '2017-3-24-15:23',
        price: 20000,
        zprice: 21001,
        Carnum: "苏A12346",
        Dtel: 13813813812,
        releasetime: '2017-3-24-9:00:00',
        lefttime: 15,
        carList: []
	},
    {
        id: 3,
        oid: 201704172223,
        cname: '客户3',
        ctel: '15081111111',
        sprovince: '江苏省',
        scity: '南京市',
        sdistrict: '浦口区',
        saddr: '南京大学金陵学院',
        stime: '2017-3-21-15:23',
        info: '钢材器械',
        eprovince: '江苏省',
        ecity: '南京市',
        edistrict: '浦口区',
        eaddr: '南京工业大学江浦校区',
        etime: '2017-3-24-15:23',
        price: 20000,
        zprice: 21000,
        Carnum: "苏A12345",
        Dtel: 13813813811,
        releasetime: '2017-3-24-9:00:00',
        lefttime: 15,
        carList: []
	},
    {
        id: 5,
        oid: 201704172225,
        cname: '客户5',
        ctel: '15081111111',
        sprovince: '江苏省',
        scity: '南京市',
        sdistrict: '浦口区',
        saddr: '南京大学金陵学院',
        stime: '2017-3-21-15:23',
        info: '钢材器械',
        eprovince: '江苏省',
        ecity: '南京市',
        edistrict: '浦口区',
        eaddr: '南京工业大学江浦校区',
        etime: '2017-3-24-15:23',
        price: 20000,
        zprice: 21000,
        Carnum: "苏A12345",
        Dtel: 13813813811,
        releasetime: '2017-3-24-9:00:00',
        lefttime: 15,
        carList: [{
                cid: 1,
                carnum: '苏A12345',
                credit: 4.5,
                dtel: 13813813811,
                cprice: 15000,
        },
            {
                cid: 2,
                carnum: '苏A12345',
                credit: 4.5,
                dtel: 13813813811,
                cprice: 15000,
        },
            {
                cid: 3,
                carnum: '苏A12345',
                credit: 4.5,
                dtel: 13813813811,
                cprice: 15000,
        }]
	},
    {
        id: 6,
        oid: 201704172226,
        cname: '客户6',
        ctel: '15081111111',
        sprovince: '江苏省',
        scity: '南京市',
        sdistrict: '浦口区',
        saddr: '南京大学金陵学院',
        stime: '2017-3-21-15:23',
        info: '钢材器械',
        eprovince: '江苏省',
        ecity: '南京市',
        edistrict: '浦口区',
        eaddr: '南京工业大学江浦校区',
        etime: '2017-3-24-15:23',
        price: 20000,
        zprice: 21000,
        Carnum: "苏A12345",
        Dtel: 13813813811,
        releasetime: '2017-3-24-9:00:00',
        lefttime: 15,
        carList: [{
                cid: 1,
                carnum: '苏A12345',
                credit: 4.5,
                dtel: 13813813811,
                cprice: 15000,
        },
            {
                cid: 2,
                carnum: '苏A12345',
                credit: 4.5,
                dtel: 13813813811,
                cprice: 15000,
        },
            {
                cid: 3,
                carnum: '苏A12345',
                credit: 4.5,
                dtel: 13813813811,
                cprice: 15000,
        }]
	},
    {
        id: 7,
        oid: 201704172227,
        cname: '客户7',
        ctel: '15081111111',
        sprovince: '江苏省',
        scity: '南京市',
        sdistrict: '浦口区',
        saddr: '南京大学金陵学院',
        stime: '2017-3-21-15:23',
        info: '钢材器械',
        eprovince: '江苏省',
        ecity: '南京市',
        edistrict: '浦口区',
        eaddr: '南京工业大学江浦校区江浦校区',
        etime: '2017-3-24-15:23',
        price: 20000,
        zprice: 21000,
        Carnum: "苏A12345",
        Dtel: 13813813811,
        releasetime: '2017-3-24-9:00:00',
        lefttime: 15,
        carList: [{
                cid: 1,
                carnum: '苏A12345',
                credit: 4.5,
                dtel: 13813813811,
                cprice: 15000,
        },
            {
                cid: 2,
                carnum: '苏A12345',
                credit: 4.5,
                dtel: 13813813811,
                cprice: 15000,
        },
            {
                cid: 3,
                carnum: '苏A12345',
                credit: 4.5,
                dtel: 13813813811,
                cprice: 15000,
        }]
	},
    {
        id: 8,
        oid: 201704172228,
        cname: '客户8',
        ctel: '15081111111',
        sprovince: '江苏省',
        scity: '南京市',
        sdistrict: '浦口区',
        saddr: '南京大学金陵学院',
        stime: '2017-3-21-15:23',
        info: '钢材器械',
        eprovince: '江苏省',
        ecity: '南京市',
        edistrict: '浦口区',
        eaddr: '南京工业大学江浦校区',
        etime: '2017-3-24-15:23',
        price: 20000,
        zprice: 21000,
        Carnum: "苏A12345",
        Dtel: 13813813811,
        releasetime: '2017-3-24-9:00:00',
        lefttime: 15,
        carList: [{
                cid: 1,
                carnum: '苏A12345',
                credit: 4.5,
                dtel: 13813813811,
                cprice: 15000,
        },
            {
                cid: 2,
                carnum: '苏A12345',
                credit: 4.5,
                dtel: 13813813811,
                cprice: 15000,
        },
            {
                cid: 3,
                carnum: '苏A12345',
                credit: 4.5,
                dtel: 13813813811,
                cprice: 15000,
        }]
	},

]


//竞价订单
app.get('/api/JJorderlist', function (req, res) {
    res.json([
        {
            id: 5,
            Jid: 1,
            cname: '客户5',
            ctel: '15081111111',
            sprovince: '江苏省',
            scity: '南京市',
            sdistrict: '浦口区',
            saddr: '南京大学金陵学院',
            stime: '2017-3-21-15:23',
            info: '钢材器械',
            price: 20000,
            releasetime: '2017-3-24-9:00:00',
            lefttime: 15
	},
        {
            id: 6,
            Jid: 2,
            cname: '客户6',
            ctel: '15081111111',
            sprovince: '江苏省',
            scity: '南京市',
            sdistrict: '浦口区',
            saddr: '南京大学金陵学院',
            stime: '2017-3-21-15:23',
            info: '钢材器械',
            price: 20000,
            releasetime: '2017-3-24-9:00:00',
            lefttime: 15
	},
        {
            id: 7,
            Jid: 3,
            cname: '客户7',
            ctel: '15081111111',
            sprovince: '江苏省',
            scity: '南京市',
            sdistrict: '浦口区',
            saddr: '南京大学金陵学院',
            stime: '2017-3-21-15:23',
            info: '钢材器械',
            price: 20000,
            releasetime: '2017-3-24-9:00:00',
            lefttime: 15
	},
        {
            id: 8,
            Jid: 4,
            cname: '客户8',
            ctel: '15081111111',
            sprovince: '江苏省',
            scity: '南京市',
            sdistrict: '浦口区',
            saddr: '南京大学金陵学院',
            stime: '2017-3-21-15:23',
            info: '钢材器械',
            price: 20000,
            releasetime: '2017-3-24-9:00:00',
            lefttime: 15
	}
	]);
});

//根据订单编号获取订单详情
app.get('/api/ordersearch', function (req, res) {
    var oid = req.param('oid');
    var obj = null;
    for (var i = 0; i < data.length; i++) {
        if (data[i].oid == oid) {
            obj = data[i];
            break;
        }
    }

    res.json(obj);
});

//获取订单详情
app.get('/api/get-order-detail', function (req, res) {
    var id = req.param('id');
    var obj = null;
    for (var i = 0; i < data.length; i++) {
        if (data[i].id == id) {
            obj = data[i];
            break;
        }
    }

    res.json(obj);
});


//获取竞价列表

app.get('/api/get-JJlist', function (req, res) {
    var id = req.param('id');
    var obj = null;
    for (var i = 0; i < data.length; i++) {
        if (data[i].id == id) {
            obj = data[i];
            break;
        }
    }

    res.json(obj);
});


//选择车辆

app.post('/api/select-car', function (req, res) {
    res.json({
        status: '选择成功'
    });
});

//选择车辆排序
app.post('/api/carsort', function (req, res) {
    var id = req.param('id');
    var obj = null;
    for (var i = 0; i < data.length; i++) {
        if (data[i].id == id) {
            obj = data[i];
            break;
        }
    }
})

//订单（进行中和已完成）
app.get('/api/orderlist', function (req, res) {
    res.json([
        {
            id: 1,
            oid: 123456, //订单号
            cname: '客户1',
            ctel: '15081111111',
            sprovince: '江苏省',
            scity: '南京市',
            sdistrict: '浦口区',
            saddr: '南京大学金陵学院',
            stime: '2017-3-21-15:23',
            eprovince: '江苏省',
            ecity: '南京市',
            edistrict: '浦口区',
            eaddr: '南京工业大学江浦校区',
            etime: ' 2017-3-24-15:24',
            info: '钢材器械',
            carnum: '苏A8888',
            flag: '1'
	},
        {
            id: 2,
            oid: 123457, //订单号
            cname: '客户2',
            ctel: '15081111111',
            sprovince: '江苏省',
            scity: '南京市',
            sdistrict: '浦口区',
            saddr: '南京大学金陵学院',
            stime: '2017-3-21-15:23',
            eprovince: '江苏省',
            ecity: '南京市',
            edistrict: '浦口区',
            eaddr: '南京工业大学江浦校区',
            etime: ' 2017-3-24-15:24',
            info: '钢材器械',
            carnum: '苏A8888',
            flag: '0'
	},
        {
            id: 3,
            oid: 123458, //订单号
            cname: '客户1',
            ctel: '15081111111',
            sprovince: '江苏省',
            scity: '南京市',
            sdistrict: '浦口区',
            saddr: '南京大学金陵学院',
            stime: '2017-3-21-15:23',
            eprovince: '江苏省',
            ecity: '南京市',
            edistrict: '浦口区',
            eaddr: '南京工业大学江浦校区',
            etime: ' 2017-3-24-15:24',
            info: '钢材器械',
            carnum: '苏A8888',
            flag: '0'
	},
        {
            id: 4,
            oid: 123459, //订单号
            cname: '客户1',
            ctel: '15081111111',
            sprovince: '江苏省',
            scity: '南京市',
            sdistrict: '浦口区',
            saddr: '南京大学金陵学院',
            stime: '2017-3-21-15:23',
            eprovince: '江苏省',
            ecity: '南京市',
            edistrict: '浦口区',
            eaddr: '南京工业大学江浦校区',
            etime: ' 2017-3-24-15:24',
            info: '钢材器械',
            carnum: '苏A8888',
            flag: '1'
	}
	]);
});

app.post('/api/allocate', function (req, res) {
    res.json({
        status: '下单成功'
    });
});

app.post('/api/cancelorder', function (req, res) {
    res.json({
        status: '取消成功'
    });
});
app.post('/api/confirmorder', function (req, res) {
    res.json({
        status: '订单已完成'
    });
});

app.post('/api/regist', function (req, res) {
    res.json({
        status: '注册成功'
    });
});

app.post('/api/login', function (req, res) {
    res.json({
        status: '登录成功'
    });
});
app.post('/api/logout', function (req, res) {
    res.json({
        status: '注销成功'
    });
});


var server = app.listen(80, function () {
    var host = server.address().address;
    var port = server.address().port;

    console.log('服务器启动 http://%s:%s', host, port);
});
